package nc.impl.dm.m4804.rule.util;

import java.util.ArrayList;
import java.util.List;
import nc.vo.dm.m4804.entity.DelivBillAggVO;
import nc.vo.dm.m4804.entity.DelivBillBVO;
import nc.vo.dm.m4804.entity.DelivBillPackVO;
import nc.vo.pub.BusinessException;
import nc.vo.scmf.dm.route.pub.IRoute;
import nc.vo.scmf.dm.route.pub.TrafficTaskVO;












public class RouteMessageUtil implements IRoute {
  private DelivBillAggVO delivBillvo;
  
  public RouteMessageUtil(DelivBillAggVO vo) {
    this.delivBillvo = vo;
  }



  public int getBVOsize() {
    return (this.delivBillvo.getDelivBillBVO()).length;
  }


  public List<TrafficTaskVO> getAddrDoc() throws BusinessException {
    if (this.delivBillvo == null)
      return null; 

    List<TrafficTaskVO> result = new ArrayList<>();
    if (this.delivBillvo.getChildrenVO() != null && (this.delivBillvo
      .getChildrenVO()).length > 0)
      result.addAll(getAddDocFromBody(this.delivBillvo.getDelivBillBVO())); 

    if (this.delivBillvo.getDelivBillPackVO() != null && (this.delivBillvo
      .getDelivBillPackVO()).length > 0)
      result.addAll(getAddDocFromPack(this.delivBillvo
            .getDelivBillPackVO())); 

    return result;
  }


  public String getRouteId() {
    if (this.delivBillvo == null)
      return null; 

    return this.delivBillvo.getParentVO().getCrouteid();
  }

  private List<TrafficTaskVO> getAddDocFromBody(DelivBillBVO[] childrenVO) {
    List<TrafficTaskVO> ref = new ArrayList<>();
    TrafficTaskVO trafficTask = null;
    for (DelivBillBVO vo : childrenVO) {
      trafficTask = new TrafficTaskVO();
      trafficTask.setSendAddrId(vo.getCsendaddrdocid());
      trafficTask.setReceiveAddrId(vo.getCreceiveaddrdocid());
      ref.add(trafficTask);
    } 
    return ref;
  }

  private List<TrafficTaskVO> getAddDocFromPack(DelivBillPackVO[] delivBillBVO) {
    List<TrafficTaskVO> ref = new ArrayList<>();
    TrafficTaskVO trafficTask = null;
    for (DelivBillPackVO vo : delivBillBVO) {
      trafficTask = new TrafficTaskVO();
      trafficTask.setSendAddrId(vo.getCsendaddrdocid());
      trafficTask.setReceiveAddrId(vo.getCreceiveaddrdocid());
      ref.add(trafficTask);
    } 
    return ref;
  }
}
